package com.lz.football.module.activity.lzteam
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.MainEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.activity.ILZTeamView;
	
	import common.item.ComGoodsItem;
	
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	
	import lz.controls.core.TitleWindow;

	/**
	 *良众队 
	 * @author lake
	 * 
	 */	
	public class LZTeamView extends TitleWindow implements ILZTeamView
	{
		/**
		 *条目列表 
		 * 
		 */		
		private var itemList :Array = [];
		/**
		 *开始按钮 
		 */		
		private var startBtn :SimpleButton;
		
		public function LZTeamView()
		{
			super();
		}
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.skin.lzteamview");
			_symbolSkin.cacheAsBitmap = true;
			startBtn = _symbolSkin.startBtn;
			//初始化宽高
			width = _symbolSkin.width;
			height = _symbolSkin.height;
			//初始化UI界面控件
			windowBg = _symbolSkin.windowBg;//背景框
			windowBg.mouseChildren = false;
			//设置可拖动
			dragEnabled = true;
			this.addChild(_symbolSkin);
			closeBtn = Reflection.createInstance("com.lz.commonUI.closeBtn");
			this.addChild(closeBtn);
			closeBtn.x = 545;
			closeBtn.y = 30;
			//设置关闭按钮
			setCloseBtn(closeBtn);
			//add event
			addEvtListener();
			//初始化奖励
			var item :ComGoodsItem;
			var i :int = 0;
			var awards :Array = [{id:92,type:4}];
			for each(var obp :Object in awards)
			{
				item = new ComGoodsItem();
				item.initUI();
				item.data = AppData.getInstance().goodsManager.getGoodsByTypeAndId(int(obp.type),int(obp.id));
				item.y = 114;
				item.x = 57 + i * 81;
				_symbolSkin.addChild(item);
				itemList.push(item);
				i ++ ;
			}
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			startBtn.addEventListener(MouseEvent.CLICK,startH);
		}
		/**
		 *开始 H 
		 * @param e
		 * 
		 */		
		private function startH(e :MouseEvent):void
		{
			AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LEAGUEMATCH_VIEW));
		}
		/**
		 * onCloseHandler
		 * @param e
		 * 
		 */		
		override protected function onCloseHandler(e :MouseEvent):void
		{
			this.dispatchEvent(new ModuleEvent(ModuleEvent.REMOVE_MODULE));
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			closeBtn.removeEventListener(MouseEvent.CLICK,onCloseHandler);
			startBtn.removeEventListener(MouseEvent.CLICK,startH);
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
			removeEvtListener();
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
			for each(var item :ComGoodsItem in itemList)
			{
				item.destroyView();
				item = null;
			}
			itemList = null;
			DisplayObjectUtil.removeAllChildren(this);
			_symbolSkin = null;
			closeBtn = null;
		}
		/**
		 *显示tab类型 
		 * @param $obj
		 * 
		 */
		public function showType($obj:Object):void
		{
		}
	}
}